<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_Product_Controller extends CI_Controller {

function __construct(){
		parent::__construct();
		$this->load->model('admin_model');
		$this->load->library('form_validation');
		session_start();
		if($this->uri->segment(2) == 'edit'){
			$this->template->set_template('admin_simple');
		}else{	
			$this->template->set_template('admin');
		}
    }
	
	function index(){
		if(isset($_SESSION['is_admin_logged_in'])){
			
			$this->load->library('pagination');
			$config['base_url'] = $this->config->config['base_url'].'/category'.(empty($parent_category_name) ? '' : "/$parent_category_name")."/$category_name/page/{page_number}/";
			$config['cur_page'] = $page_number;
			$config['total_rows'] = $category_product_count;
			$config['per_page'] = $limit;
			$config['rel'] = 'noindex,follow';
			$config['first_link'] = '&laquo;';
			$config['last_link'] = '&raquo;';
			$config['next_link'] = '&rsaquo;';
			$config['prev_link'] = '&lsaquo;';
			
			$this->pagination->initialize($config); 
		
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_product_block', array('product' => $this->admin_model->get_product_lists(), 'pagination' => $this->pagination->create_links()), FALSE);
			$this->render_template = TRUE;
		}else{
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "product";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
	
	function edit($id){
		if(isset($_SESSION['is_admin_logged_in'])){
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('content', 'admin_category_edit', array('category' => $this->admin_model->get_category_by_id($id)), FALSE);
			$this->render_template = TRUE;
		}else{
			$this->template->set_template('admin');
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "product";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
	
	function update(){
		if(isset($_SESSION['is_admin_logged_in'])){
			$result = $this->admin_model->update_category_by_id();
			$this->index();
		}else{
			$this->template->set_template('admin');
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "product";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
}

/* End of file admin_product_controller.php */
/* Location: ./application/controllers/admin_product_controller.php */